package com.kpmg.datalake.web.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

import javax.annotation.Resource;
import javax.sql.DataSource;

/**
 * @author Alex.zhao [alex.zhao@kpmg.com]
 * @since Created on azhao6 on 2018-08-08 22:44:58
 */
@Configuration
public class QuartzConfig {

    @Resource
    private DataSource dataSource;


    @Bean
    public SchedulerFactoryBean init() {
        SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
        //设置覆盖已存在的任务
        schedulerFactoryBean.setOverwriteExistingJobs(true);
        //项目启动完成后，等待2秒后开始执行调度器初始化
        schedulerFactoryBean.setStartupDelay(2);
        //设置调度器自动运行
        schedulerFactoryBean.setAutoStartup(true);

        schedulerFactoryBean.setWaitForJobsToCompleteOnShutdown(false);

        return schedulerFactoryBean;
    }
}
